<template>
  <div>
    <c-table-box
      ref="cTableBox"
      hide-func
      :other-filters="otherFilters"
      :table-config="tableConfig"
      table-row-key="id"
      :index="false"
      @selection-change="selectionChange"
    >
      <el-table-column fixed="left" type="selection" :selectable="canSelect" />
      <template #btn>
        <c-permission v-if="type==='all'" code="all">
          <c-button opt-code="add" type="primary" @click="handleAdd">新增</c-button>
          <c-button opt-code="exception" type="primary" @click="handleException">发起异常</c-button>
          <c-button opt-code="edit" type="primary" @click="handleUrgentEdit">加急维护</c-button>
          <c-button opt-code="import" type="primary" @click="handleImport">导入</c-button>
          <c-button opt-code="export" type="primary" @click="handleExport">导出模板</c-button>
          <c-button opt-code="changePerson" type="primary" @click="handleChangePerson">变更人员</c-button>
          <c-button opt-code="drawingUpload" type="primary" @click="handledrawingUpload(1)">单号上传</c-button>
        </c-permission>
        <c-permission v-if="type==='uploadPic'" code="uploadPic">
          <c-button opt-code="uploadPic" type="primary" @click="handleUploadPic">上传配图</c-button>
        </c-permission>
        <c-permission v-if="type==='distribute'" code="distribute">
          <c-button opt-code="distribute" type="primary" @click="handleDistribute">分配设计师</c-button>
        </c-permission>
        <c-permission v-if="type==='designTask'" code="designTask">
          <c-button opt-code="designTask" type="primary" @click="handleTrans">外观回传</c-button>
        </c-permission>
        <!-- 设计单位确认 -->
        <c-permission v-if="type==='studioConfirm'" code="studioConfirm">
          <c-button opt-code="studioConfirm" type="primary" @click="handleDrawingConfirm">图纸确认</c-button>
        </c-permission>
        <c-permission v-if="type==='lastdrawingSubmit'" code="lastdrawingSubmit">
          <c-button opt-code="lastdrawingSubmit" type="primary" @click="handleLastUp">图纸上传</c-button>
        </c-permission>
        <c-permission v-if="type==='transDistribute'" code="transDistribute">
          <c-button opt-code="transDistribute" type="primary" @click="handleTransDistribute">转化分配</c-button>
        </c-permission>
        <c-permission v-if="type==='crmOrder'" code="crmOrder">
          <c-button opt-code="crmOrder" type="primary" @click="handleCrmOrder">CRM下单</c-button>
        </c-permission>
        <c-permission v-if="type==='confirmDrawing'" code="confirmDrawing">
          <c-button opt-code="confirmDrawing" type="primary" @click="handleConfirmDrawing">确图</c-button>
        </c-permission>
        <c-permission v-if="type==='drawingUpload'" code="drawingUpload">
          <c-button opt-code="drawingUpload" type="primary" @click="handledrawingUpload">上传</c-button>
        </c-permission>
        <c-permission v-if="type==='curtainOrder'" code="curtainOrder">
          <c-button opt-code="curtainOrder" type="primary" @click="curtainOrder">窗帘下单</c-button>
        </c-permission>
        <c-permission v-if="type==='sapOrder'" code="sapOrder">
          <c-button opt-code="sapOrder" type="primary" @click="handleUnlock">解锁</c-button>
        </c-permission>
      </template>

    </c-table-box>
    <!-- 发起异常 -->
    <el-dialog
      ref="refDlg"
      title="发起异常"
      :visible.sync="exceptionVisible"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :before-close="closeDialog"
      width="50%"
      @close="closeDialog"
    >
      <el-form ref="refForm" :rules="exceptionRules" :model="formData" size="mini" label-width="100px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="配图任务号:" prop="taskCode">
              <el-input v-model="formData.taskCode" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="配图进度:" prop="drawingSchedule">
              <el-select
                v-model="formData.drawingSchedule"
                style="width: 100%"
                disabled
              >
                <el-option
                  v-for="item in drawingScheduleList"
                  :key="item.dictCode"
                  :label="item.dictName"
                  :value="item.dictCode"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="门店编码:" prop="shopCode">
              <el-input v-model="formData.shopCode" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="门店名称:" prop="shopName">
              <el-input v-model="formData.shopName" disabled />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="门店建设项目号:" prop="constCode">
              <el-input v-model="formData.constCode" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="异常类型:" prop="exceptionType">
              <el-select
                v-model="formData.exceptionType"
                placeholder="请选择"
                style="width: 100%"
              >
                <el-option
                  v-for="item in exceptionList"
                  :key="item.dictCode"
                  :disabled="isDisabled(item.dictName)"
                  :label="item.dictName"
                  :value="item.dictCode"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="['D','E'].includes(formData.exceptionType)">
          <el-col :span="12">
            <el-form-item :rules="[{ required: ['D','E'].includes(formData.exceptionType), message: '请选择', trigger: 'change' }]" label="异常配图进度:" prop="exceptionDrawingSchedule">
              <el-select
                v-model="formData.exceptionDrawingSchedule"
                style="width: 100%"
              >
                <el-option
                  v-for="item in drawingScheduleList"
                  :key="item.dictCode"
                  :label="item.dictName"
                  :value="item.dictCode"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col v-show="formData.exceptionType==='D'" :span="12">
            <el-form-item label="复尺时间:" prop="rulerTime">
              <el-date-picker
                v-model="formData.rulerTime"
                style="width: 100%"
                value-format="yyyy-MM-dd HH:mm:ss"
                align="right"
                type="datetime"
                placeholder="选择日期"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="异常原因:" prop="exceptionRemark">
              <el-input
                v-model="formData.exceptionRemark"
                maxlength="1000"
                show-word-limit
                :autosize="{ minRows: 4, maxRows: 4}"
                type="textarea"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" @click="closeDialog">取 消</el-button>
        <el-button size="mini" type="primary" @click="submitException">确 定</el-button>
      </span>
    </el-dialog>
    <urgent-edit v-if="showEditDlg" ref="formDlg" :visible.sync="showEditDlg" :detail-data="activeData" @success="refreshTable" />
    <drawing-file v-if="showDrawingFile" :row-data="activeData" :visible.sync="showDrawingFile" />
    <div>
      <import-files v-if="importVisible" title="导入" :visible.sync="importVisible" :config="fileImportConfig" @success="refreshTable" />
      <export-files v-if="exportVisible" title="导出" :config="exportConfig" :visible.sync="exportVisible" />
    </div>
    <el-dialog
      title="变更人员"
      :visible.sync="showChangeDlg"
      width="30%"
      center
    >
      <el-form ref="refForm1" :model="personForm" size="mini" label-width="90px">
        <el-row>
          <el-col>
            <el-form-item label="配置设计师:" prop="drawingDesigner">
              <input-with-dialog
                v-model="drawingDesigner"
                :props="{label:'userName',value:'account'}"
                multiple
                :config="{
                  title:'设计师',
                  width:'600px',
                  interfacePath:`/slm-admin/api/v1/user/listUsers`,
                  method:'post',
                  filtersRaw:[],
                  paramsRaw:{},
                  setting:[
                    {prop:'account',title:'编码'},
                    {prop:'userName',title:'名称'}
                  ]
                }"
                @change="handleChangeDesigner"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <el-form-item label="转化专员:" prop="drawingChanger">
              <input-with-dialog
                v-model="drawingChanger"
                :props="{label:'userName',value:'account'}"
                multiple
                :config="{
                  title:'图纸转化专员',
                  width:'600px',
                  interfacePath:`/slm-admin/api/v1/user/listUsers`,
                  method:'post',
                  filtersRaw:[],
                  paramsRaw:{},
                  setting:[
                    {prop:'account',title:'编码'},
                    {prop:'userName',title:'名称'}
                  ]
                }"
                @change="handleChangePeople"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="showChangeDlg = false">取 消</el-button>
        <el-button type="primary" @click="handleSavePerson">确 定</el-button>
      </span>
    </el-dialog>
    <upload-pic
      v-if="uploadDlgVisible"
      ref="refDlg"
      :detail="activeData"
      :visible.sync="uploadDlgVisible"
      @success="refreshTable"
    />
    <const-dlg v-if="dialogVisible" :visible.sync="dialogVisible" @success="refreshTable" />

    <!-- <upload-pic ></upload-pic> -->
  </div>
</template>
<script>
import uploadPic from './component/UploadPicDlg'
import constDlg from './component/ConstCodeDlg'
import drawingFile from './component/DrawingFile'
import urgentEdit from './UrgentEdit'
import { otherFiltersItem } from '@/utils'
import { getDictByPatchType } from '@/api/dataDict'
import { saveException, editPersonData, saveAutoTask } from '@/api/autoDesignTask'
import { shopConstructPage } from '@/api/shopDesignTask'
export default {
  name: 'List',
  components: { urgentEdit, drawingFile, uploadPic, constDlg },
  props: {
    type: {
      type: String,
      default: ''
    },
    isSelect: {
      type: Boolean,
      default: false
    },
    activeType: {
      type: String,
      default: ''
    },
    searchFilters: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      dialogVisible: false,
      uploadDlgVisible: false,
      personForm: { configurationDesigner: '', drawingDesignerCode: '', drawingChanger: '',
        drawingChangerCode: '', id: '' },
      exportVisible: false,
      importVisible: false,
      showChangeDlg: false,
      activeData: {},
      exceptionList: [], // 异常类型
      drawingScheduleList: [], // 配图进度
      exceptionRules: {
        exceptionType: [
          { required: true, message: '请选择异常类型', trigger: 'blur' }
        ],
        exceptionRemark: [
          { required: false, message: '请填写异常原因', trigger: 'blur' }
        ]
      },
      handlefilters: [],
      formData: {
        exceptionType: '',
        exceptionRemark: '',
        exceptionDrawingSchedule: '',
        rulerTime: ''// 复尺时间
      }, // 异常表单
      exceptionVisible: false, // 异常弹窗
      tableConfig: {
        interfacePath: `${process.env.VUE_APP_BASE_API}/api/v1/autonomyDesign/page`,
        buttonGroupCode: 'default',
        hideSearchBar: true,
        tabIndex: 0,
        apiHeader: {
          'Permission-perCode': 'auto_design_task',
          'Permission-App': 'slm'
        },
        pageSize: 10,
        order: 'desc',
        // sort: 'createTime',
        // 表格字段动态配置
        setting: [
          {
            prop: 'taskCode',
            label: '配图任务编号',
            minWidth: '160',
            className: 'btn-green',
            isButton: true,
            clickFun: this.handleDetail
          },
          {
            prop: 'constCode',
            label: '门店建设项目号',
            minWidth: '140'
          },
          {
            prop: 'sourceCode',
            label: '任务来源编号',
            minWidth: '140'
          },
          {
            prop: 'shopState',
            label: '门店建设状态',
            propEnum: {
              domainCode: 'marketing',
              appCode: 'slm',
              dictTypeCode: 'CONST_STATE'
            },
            minWidth: '125'
          },
          {
            prop: 'drawingSchedule',
            label: '配图进度',
            minWidth: '125',
            propEnum: {
              domainCode: 'marketing',
              appCode: 'slm',
              dictTypeCode: 'SLM_DRAWING_PROGRESS'
            }
          },
          {
            prop: 'taskState',
            label: '任务状态',
            minWidth: '110',
            propEnum: {
              domainCode: 'marketing',
              appCode: 'slm',
              dictTypeCode: 'SLM_DRAWING_STATUS'
            }
          },
          {
            prop: 'shopCode',
            label: '门店编码',
            minWidth: '110'
          },
          {
            prop: 'shopName',
            label: '门店名称',
            minWidth: '110'
          },
          {
            prop: 'sapCode',
            label: 'SAP编号',
            minWidth: '110'
          },
          {
            prop: 'sapCreateTime',
            label: 'SAP账号创建时间',
            minWidth: '110'
          },
          {
            prop: 'cabinetPermission',
            label: '有无橱柜权限',
            minWidth: '110',
            formatData: ({ cabinetPermission }) => {
              if (cabinetPermission === 0 || cabinetPermission === 1) return cabinetPermission === 0 ? '否' : '是'
              else ''
            }
          },
          {
            prop: 'wardrobePermission',
            label: '有无衣柜权限',
            minWidth: '110',
            formatData: ({ wardrobePermission }) => {
              if (wardrobePermission === 0 || wardrobePermission === 1) return wardrobePermission === 0 ? '否' : '是'
              else ''
            }
          },
          {
            prop: 'businessType',
            label: '业务类型',
            minWidth: '110'
          },
          {
            prop: 'businessStatus',
            label: '门店营业状态',
            minWidth: '110',
            propEnum: {
              domainCode: 'marketing',
              appCode: 'slm',
              dictTypeCode: 'SHOP_BIZ_STATE'
            }
          },
          {
            prop: 'shopLevel',
            label: '店面等级',
            propEnum: {
              domainCode: 'marketing',
              appCode: 'slm',
              dictTypeCode: 'SHOP_LEVEL_CODE'
            },
            minWidth: '110'
          },

          {
            prop: 'urgent',
            label: '加急',
            minWidth: '110',
            render: function(createElement, rows) {
              if (rows.urgent) {
                return (<div>
                  <div class='colorSetRed'>
                    {rows.urgent}</div>
                </div>
                )
              }
              return ''
            }
          },
          {
            prop: 'rulerConfirmTime',
            label: '复尺确认时间',
            minWidth: '120'
          },
          {
            prop: 'unLockTime',
            label: '解锁时间',
            minWidth: '120'
          },
          {
            prop: 'drawingChanger',
            label: '转化专员',
            minWidth: '120'
          },
          {
            prop: 'drawingChangeTime',
            label: '转化分配时间',
            minWidth: '120'
          },
          {
            prop: 'productFinalOrderTime',
            label: '转化下单时间',
            minWidth: '120'
          },
          {
            prop: 'enterTime',
            label: '进场时间',
            minWidth: '120'
          },
          {
            prop: 'decorationSchedule',
            label: '装修进度',
            propEnum: {
              domainCode: 'marketing',
              appCode: 'slm',
              dictTypeCode: 'DECORATION_SCHEDULE'
            },
            minWidth: '120'

          },
          {
            prop: 'drawingCollectTime',
            label: '上传配图确认时间',
            minWidth: '120'
          },
          {
            prop: 'drawingAllocationTime',
            label: '配图分配时间',
            minWidth: '120'
          },
          {
            prop: 'configurationDesigner',
            label: '配置设计师',
            minWidth: '120'
          }, {
            prop: 'backFacadeTime',
            label: '回传外观时间',
            minWidth: '120'
          }, {
            prop: 'customizeArea',
            label: '定制面积',
            minWidth: '120'
          }, {
            prop: 'productNum',
            label: '产品总数',
            minWidth: '120'
          }, {
            prop: 'autonomyDesignNum',
            label: '自主设计个数',
            minWidth: '120'
          },
          {
            prop: 'confirmResult',
            label: '设计单位确认结果',
            minWidth: '120',
            formatData: ({ confirmResult }) => {
              if (confirmResult === '2' || confirmResult === '1') return confirmResult === '1' ? '部分' : '全部'
              else confirmResult
            }
          }
        ]
      },
      tableSelected: [],
      typeFilters: [],
      drawingChanger: [],
      drawingDesigner: [],
      state: '',
      id: '',
      showDrawingFile: false,
      showEditDlg: false,
      loading: false
    }
  },
  computed: {
    otherFilters() {
      return [...this.searchFilters, ...this.typeFilters]
    },
    selectedIds() {
      return this.tableSelected.map(row => {
        return row.id
      })
    },
    exportConfig() {
      return [
        {
          code: 'export',
          name: '自主设计模板',
          dataApi: '/slm-admin/api/v1/autonomyDesign/export?type=0',
          selectedRows: this.tableSelected,
          paramsRaw: {},
          filtersRaw: this.otherFilters,
          queryField: 'id'
        }
      ]
    },
    fileImportConfig() {
      return [{
        code: 'import',
        name: '自主设计',
        async: false,
        apiUrl: '/slm-admin/api/v1/autonomyDesign/importExcel?type=0'
      }]
    }
  },
  watch: {
    type: {
      handler(v) {
        this.setOtherFilters(v)
      },
      immediate: true
    },
    searchFilters: {
      handler(v) {
        if (this.activeType !== this.type) return
        this.refreshTable('')
      }
    }
  },
  activated() {
    if (this.ready && this.refreshTable) {
      this.refreshTable()
    }
  },
  deactivated() {
    this.ready = true
  },
  created() {
    this.getDictByPatchTypeAll()
  },
  methods: {
    handleChangePeople(data) {
      if (data && data.length > 0) {
        const list1 = data.map(v => v.userName)
        const list2 = data.map(v => v.account)
        this.$set(this.personForm, 'drawingChanger', list1.join(','))
        this.$set(this.personForm, 'drawingChangerCode', list2.join(','))
      } else {
        this.$set(this.personForm, 'drawingChanger', '')
        this.$set(this.personForm, 'drawingChangerCode', '')
      }
    },
    handleChangeDesigner(data) {
      if (data && data.length > 0) {
        const list1 = data.map(v => v.userName)
        const list2 = data.map(v => v.account)
        this.$set(this.personForm, 'configurationDesigner', list1.join(','))
        this.$set(this.personForm, 'drawingDesignerCode', list2.join(','))
      } else {
        this.$set(this.personForm, 'configurationDesigner', '')
        this.$set(this.personForm, 'drawingDesignerCode', '')
      }
    },
    isDisabled(dictName) {
      // 门店建设状态为正常、任务状态为正常时，发起异常可选暂停、终止、其他、复尺；任务状态为暂停时，发起异常可选恢复、终止
      if (this.tableSelected.length === 0) return false
      if (this.tableSelected[0].shopState === 'A' && this.tableSelected[0].taskState === 'A') {
        const str = '配图暂停、配图终止、其他、复尺'
        if (!str.includes(dictName)) return true
      } else if (this.tableSelected[0].taskState === 'B') {
        if (!'配图恢复、配图终止'.includes(dictName)) return true
      }
      return false
    },
    canSelect(row, index) {
      /**
       * 1，不包含整体橱柜，包含全屋定制的时候，有衣柜权限才可选
       * 2，不包含全屋定制，包含整体橱柜的时候，有橱柜权限才可选
       * 3，既包含全屋定制又包含整体橱柜的时候，才可选
       * 除开这些情况都不可选
       */
      // 全屋定制、多功能墙面、卫浴、窗帘，有衣柜权限才可选
      // 整体橱柜，有橱柜权限才可选
      // 橱柜+其他任意，必须有衣柜+橱柜权限才可选
      if (!this.isSelect || row.drawingSchedule !== 'E') return true
      if (row.businessStatus === '4') return false
      else if (row.businessType) {
        const flag1 = row.businessType.includes('全屋定制') || row.businessType.includes('多功能墙面') || row.businessType.includes('卫浴') || row.businessType.includes('窗帘')
        if (flag1 && row.wardrobePermission) {
          return true
        } else if (row.businessType === '整体橱柜' && row.cabinetPermission) {
          return true
        } else if (row.businessType.includes('整体橱柜') && row.businessType.includes(',') && row.wardrobePermission && row.cabinetPermission) {
          return true
        } else {
          return false
        }
      }

      // if (!this.isSelect || row.drawingSchedule !== 'E') return true
      // else {
      //   if (!row.businessType.includes('整体橱柜') && row.businessType.includes('全屋定制') && row.wardrobePermission) {
      //     return true
      //   } else if (!row.businessType.includes('全屋定制') && row.businessType.includes('整体橱柜') && row.cabinetPermission) {
      //     return true
      //   } else if (row.businessType.includes('全屋定制') && row.businessType.includes('整体橱柜') && row.cabinetPermission && row.wardrobePermission) {
      //     return true
      //   } else {
      //     return false
      //   }
      // }
    },
    handleImport() {
      this.importVisible = true
    },
    handleExport() {
      this.exportVisible = true
    },
    // 单号上传
    handleUploadSerial() {

    },
    // 变更人员
    handleChangePerson() {
      if (!this.singleJudge(this.tableSelected, '变更', true)) {
        return
      }
      const { configurationDesigner, drawingDesignerCode, drawingChanger, drawingChangerCode, id } = this.tableSelected[0]
      this.personForm = { configurationDesigner, drawingDesignerCode, drawingChanger, drawingChangerCode, id }

      this.drawingChanger = [{ value: this.personForm.drawingChangerCode || '', label: this.personForm.drawingChanger || '' }]
      this.drawingDesigner = [{ value: this.personForm.drawingDesignerCode || '', label: this.personForm.configurationDesigner || '' }]
      this.showChangeDlg = true
    },
    handleException() {
      if (!this.singleJudge(this.tableSelected, '发起异常', true)) {
        return
      }
      if (this.tableSelected[0].shopState === 'B' || this.tableSelected[0].taskState === 'C') {
        this.$message.warning('门店建设状态或者任务状态为终止，不可发起异常')
        return
      }

      this.formData = { ... this.tableSelected[0], ...this.formData }
      this.exceptionVisible = true
    },
    // 修改加急
    handleUrgentEdit() {
      if (!this.singleJudge(this.tableSelected, '加急维护', true)) {
        return
      }
      this.activeData = this.tableSelected[0]
      this.showEditDlg = true
    },
    selectionChange(v) {
      this.tableSelected = v
    },
    // 设置过滤条件
    setOtherFilters(v) {
      switch (v) {
        case 'all':
          this.typeFilters = []
          break
        case 'uploadPic':
          // 显示“上传配图”
          this.typeFilters = [otherFiltersItem('drawingSchedule', 'L', '='), otherFiltersItem('taskState', 'A', '='), otherFiltersItem('shopState', 'A', '=')]
          break
        case 'distribute':
          // 显示“待分配”
          this.typeFilters = [otherFiltersItem('drawingSchedule', 'A', '='), otherFiltersItem('taskState', 'A', '='), otherFiltersItem('shopState', 'A', '=')]
          break
        case 'designTask':
          // 显示“设计任务”
          this.typeFilters = [otherFiltersItem('drawingSchedule', 'B', '='), otherFiltersItem('taskState', 'A', '='), otherFiltersItem('shopState', 'A', '=')]
          break
        case 'studioConfirm':
          // 显示“设计单位确认”
          this.typeFilters = [otherFiltersItem('drawingSchedule', 'C', '='), otherFiltersItem('taskState', 'A', '='), otherFiltersItem('shopState', 'A', '=')]
          break
        case 'lastdrawingSubmit':
          // 显示“终版图纸上传”
          this.typeFilters = [otherFiltersItem('drawingSchedule', 'D', '='), otherFiltersItem('taskState', 'A', '='), otherFiltersItem('shopState', 'A', '=')]
          break
        case 'transDistribute':
          // 显示“转化分配”
          this.typeFilters = [otherFiltersItem('drawingSchedule', 'E', '='), otherFiltersItem('taskState', 'A', '='), otherFiltersItem('shopState', 'A', '=')]
          break
        case 'crmOrder':
          // 显示“CRM下单”
          this.typeFilters = [otherFiltersItem('drawingSchedule', 'F', '='), otherFiltersItem('taskState', 'A', '='), otherFiltersItem('shopState', 'A', '=')]
          break
        case 'confirmDrawing':
          // 显示“确图”
          this.typeFilters = [otherFiltersItem('drawingSchedule', 'G', '='), otherFiltersItem('taskState', 'A', '='), otherFiltersItem('shopState', 'A', '=')]
          break
        case 'drawingUpload':
          // 显示“单号图纸上传”
          this.typeFilters = [otherFiltersItem('drawingSchedule', 'K', '='), otherFiltersItem('taskState', 'A', '='), otherFiltersItem('shopState', 'A', '=')]
          break
        case 'curtainOrder':
          // 显示“窗帘下单”，窗帘下单页签只显示业务类型包含【窗帘】且任务进度为SAP下单的数据
          this.typeFilters = [otherFiltersItem('isInclusiveCurtain', '1', '='), otherFiltersItem('drawingSchedule', 'I', '='),
            otherFiltersItem('taskState', 'A', '='), otherFiltersItem('shopState', 'A', '=')]
          break
        case 'sapOrder':
          // 显示“SAP下单”
          this.typeFilters = [otherFiltersItem('drawingSchedule', 'I', '='), otherFiltersItem('taskState', 'A', '='), otherFiltersItem('shopState', 'A', '=')]
          break
      }
    },
    async getDictByPatchTypeAll() {
      const { SLM_EXCEPTION_TYPE, SLM_DRAWING_PROGRESS } = await getDictByPatchType(['SLM_EXCEPTION_TYPE', 'SLM_DRAWING_PROGRESS'])
      this.exceptionList = SLM_EXCEPTION_TYPE
      this.drawingScheduleList = SLM_DRAWING_PROGRESS
    },
    // 刷新表格
    refreshTable(v = 'onPage') {
      this.$nextTick(() => {
        this.$refs.cTableBox.initTableData(v)
      })
    },
    handleAdd() {
      this.$prompt('请输入门店建设项目号', {
        confirmButtonText: '确定',
        closeOnClickModal: false,
        cancelButtonText: '取消',
        beforeClose: (action, instance, done) => {
          if (action === 'confirm') {
            instance.confirmButtonLoading = true
            instance.confirmButtonText = ''
            shopConstructPage(instance.inputValue).then(res => {
              if (res.success && res.data.records.length > 0) {
                const form = { constCode: instance.inputValue }
                saveAutoTask(form).then(res => {
                  if (res.success) {
                    this.$message.success('操作成功')
                    instance.confirmButtonLoading = false
                    done()
                  }
                  this.refreshTable()
                })
              } else {
                this.$message.warning('请输入正确的门店建设项目号')
                instance.confirmButtonLoading = false
              }
            })
          } else {
            instance.confirmButtonLoading = false
            done()
          }
        }
      })
    },
    handleSavePerson() {
      // this.$refs['refForm1'].validate((valid) => {
      //   if (valid) {
      editPersonData(this.personForm).then(res => {
        if (res.success) {
          this.$message.success('操作成功')
          this.showChangeDlg = false
          this.refreshTable()
          this.personForm = { configurationDesigner: '', drawingDesignerCode: '', drawingChanger: '', drawingChangerCode: '', id: '' }
        }
      })
      //   }
      // })
    },
    // 上传配图
    handleUploadPic() {
      if (!this.singleJudge(this.tableSelected, '上传', true)) {
        return
      }
      this.activeData = this.tableSelected[0]
      this.uploadDlgVisible = true
      // this.$router.push({ name: 'EditAutoDesignTask', query: { id: this.tableSelected[0].id }})
    },
    // 新增/编辑
    handleDistribute() {
      if (!this.singleJudge(this.tableSelected, '分配', true)) {
        return
      }
      this.$router.push({ name: 'EditAutoDesignTask', query: { id: this.tableSelected[0].id }})
    },
    // 外观回传
    handleTrans() {
      if (!this.singleJudge(this.tableSelected, '外观回传', true)) {
        return
      }
      this.$router.push({ name: 'FacadeBack', query: { id: this.tableSelected[0].id }})
    },
    // 图纸确认
    handleDrawingConfirm() {
      if (!this.singleJudge(this.tableSelected, '图纸确认', true)) {
        return
      }
      this.$router.push({ name: 'DrawingConfirm', query: { id: this.tableSelected[0].id }})
    },
    // 终版图纸上传
    handleLastUp() {
      if (!this.singleJudge(this.tableSelected, '上传', true)) {
        return
      }
      this.$router.push({ name: 'LastDrawingUp', query: { id: this.tableSelected[0].id }})
    },
    // 转化分配
    handleTransDistribute() {
      if (!this.singleJudge(this.tableSelected, '转化分配', true)) {
        return
      }
      this.$router.push({ name: 'TransDistribute', query: { id: this.tableSelected[0].id }})
    },
    // CRM下单
    handleCrmOrder() {
      if (!this.singleJudge(this.tableSelected, 'CRM下单', true)) {
        return
      }
      this.$router.push({ name: 'CrmOrder', query: { id: this.tableSelected[0].id }})
    },
    // 确图
    handleConfirmDrawing() {
      if (!this.singleJudge(this.tableSelected, '确图', true)) {
        return
      }
      this.$router.push({ name: 'ConfirmDrawing', query: { id: this.tableSelected[0].id }})
    },
    handledrawingUpload(type) {
      if (!this.singleJudge(this.tableSelected, '上传', true)) {
        return
      }
      if (!type || (type && this.tableSelected[0].taskState === 'A' && (this.tableSelected[0].drawingSchedule === 'K' || this.tableSelected[0].drawingSchedule === 'I' || this.tableSelected[0].drawingSchedule === 'J'))) {
        this.activeData = this.tableSelected[0]
        this.showDrawingFile = true
      } else {
        this.$message.warning('当前数据不符合单号上传条件')
      }
    },
    curtainOrder() {
      if (!this.singleJudge(this.tableSelected, '窗帘下单', true)) {
        return
      }
      this.$router.push({ name: 'CurtainOrder', query: { id: this.tableSelected[0].id }})
    },
    // SAP解锁
    handleUnlock() {
      if (!this.singleJudge(this.tableSelected, '解锁', true)) {
        return
      }
      this.$router.push({ name: 'Unlock', query: { id: this.tableSelected[0].id }})
    },
    handleDetail(data) {
      this.$router.push({ name: 'DetailAutoDesignTask', query: { id: data.id }})
    },
    closeDialog() {
      this.exceptionVisible = false
      this.clearForm()
    },
    clearForm() {
      this.formData = {
        exceptionType: '',
        exceptionDrawingSchedule: '',
        exceptionRemark: '',
        rulerTime: ''// 复尺时间
      }
    },
    // 设置表格多选行高亮
    tableRowClassName({ row, rowIndex }) {
      const filterArr = this.tableSelected.filter(item => item.id === row.id)
      return filterArr.length > 0 ? 'selected-highlight' : ''
    },
    // 提交发起异常
    submitException() {
      this.$refs['refForm'].validate((valid) => {
        if (valid) {
          if (this.formData.exceptionType !== 'D') this.formData.rulerTime = ''
          if (this.formData.exceptionType !== 'D' && this.formData.exceptionType !== 'E') this.formData.exceptionDrawingSchedule = ''
          saveException(this.formData).then(res => {
            if (res.success === 1) {
              this.$message({
                message: '操作成功',
                type: 'success'
              })
              this.refreshTable()
              this.closeDialog()
            }
          }).catch(() => {
          })
        }
      })
    },
    clearSearch() {

    },
    // 获取搜索条件
    handleSearch(data) {
      this.handlefilters = [...data.filtersRaw]
    }
  }
}
</script>
<style lang="scss" scoped>
.colorSetRed{
  color: red;
}
</style>
